#include "netframeimpl.h"
#include "dnsimpl.h"
#include "websocketimpl.h"
#include "httpimpl.h"
#include "modbusimpl.h"

CNetFrameImpl::CNetFrameImpl(void)
{
}
CNetFrameImpl::~CNetFrameImpl(void)
{
    logi("CNetImpl::~CNetImpl");
}
HRESULT CNetFrameImpl::Init(IBase* pRot, IBase* pBase)
{
    rc_error(pRot != NULL, E_FAIL);
    return pRot->QueryInterface(IID_IRot, (void**)&m_pRot);
}
HRESULT CNetFrameImpl::Uninit()
{
    HRESULT hr = S_OK;

    return hr;
}
HRESULT CNetFrameImpl::Start(_pid_t pid, unsigned int type)
{
    HRESULT hr = S_OK;

    hr = m_pRot->GetObject(CLSID_CAsynFrame, IID_IAsynFrame, (IBase**)&m_pIAsynFrame);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(m_pIAsynFrame.m_p != INULL, E_FAIL);

    return hr;
}
HRESULT CNetFrameImpl::Stop(unsigned int exit)
{
    HRESULT hr = S_OK;


    return hr;
}
HRESULT CNetFrameImpl::Create(int type, IBase** pBase)
{
    rc_error(m_pIAsynFrame.m_p != INULL, E_FAIL);

    HRESULT hr = S_OK;

    if (type == protocol_dns) {
        CDnsImpl* pDns = ALLOC_NEW CDnsImpl();
        rc_error(pDns != NULL, E_FAIL);

        hr = pDns->init_class(m_pIAsynFrame);
        rc_error(hr == S_OK, E_FAIL);

        return pDns->QueryInterface(IID_IDns, (void**)pBase);

    } else if (type == protocol_websocket) {
        CWebSocketImpl* pWebSocket = ALLOC_NEW CWebSocketImpl();
        rc_error(pWebSocket != NULL, E_FAIL);

    } else if (protocol_modbus == type) {
        return E_FAIL;

    } else if (protocol_http == type || protocol_https == type) {
        CHttpIImpl* pObj = ALLOC_NEW CHttpIImpl();
        rc_error(pObj != NULL, E_FAIL);
        pObj->AddRef();

        return pObj->QueryInterface(IID_IHttp, (void**)pBase);
    } else {
    }
    return S_OK;
}
